import * as gulp from 'gulp';
import {join} from 'path';
import * as merge from 'merge-stream';

import Config from '../../config';

/**
 * Executes the build task, copying all TypeScript files over to the `dist/tmp` directory.
 */

function copyServerAssets(){
    return gulp.src([
        join(Config.SERVER_SRC, '**/*.*'),
        '!' + join(Config.CLIENT_SRC),
        '!' + join(Config.SERVER_SRC, '**/*.ts'),
        '!' + join(Config.SERVER_SRC, '**/*.scss'),
        '!' + join(Config.SERVER_SRC, 'tsconfig.json')
    ])
        .pipe(gulp.dest(Config.SERVER_DEST));
}

function copyClientAssets(){
    return gulp.src([
        join(Config.CLIENT_SRC, '**/*.ts'),
        join(Config.CLIENT_SRC, '**/*.html'),
        join(Config.CLIENT_SRC, '**/*.json'),
    ]).pipe(gulp.dest(Config.TMP_NG_DIR));
}


function copyServerTmp(){
    return gulp.src([
        join(Config.SERVER_SRC, 'code/*.ts'),
        join(Config.SERVER_SRC, 'models/*.ts'),
        join(Config.SERVER_SRC, 'utils/regions/*.ts'),
    ],{base:"./src"}).pipe(gulp.dest(Config.TMP_DIR));
}


export = () => {
    return merge(copyServerAssets(),copyClientAssets(),copyServerTmp());
};



